package com.xbfinal.ggkt.vod.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xbfinal.ggkt.model.vod.Teacher;
import com.xbfinal.ggkt.result.Result;
import com.xbfinal.ggkt.vo.vod.TeacherQueryVo;
import com.xbfinal.ggkt.vod.mapper.TeacherMapper;
import com.xbfinal.ggkt.vod.service.TeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author xbfinal
 * @since 2022-11-21
 */
@Service
public class TeacherServiceImpl extends ServiceImpl<TeacherMapper, Teacher> implements TeacherService {
    @Override
    public Page<Teacher> findQueryPage(long current, long limit, TeacherQueryVo teacherQueryVo) {

        QueryWrapper<Teacher> wrapper = new QueryWrapper<>();//查询封装对象
        Page<Teacher> pageParam =new Page<>(current,limit);
        //判断对象是否为空
        if(teacherQueryVo == null){
            //查询全部
            Page<Teacher> page = this.page(pageParam);
            return page;
        }

        String name = teacherQueryVo.getName();//讲师名称
        Integer level = teacherQueryVo.getLevel();//讲师头衔
        String joinDateBegin = teacherQueryVo.getJoinDateBegin();//开始时间
        String joinDateEnd = teacherQueryVo.getJoinDateEnd();//结束时间
        //判断空值

        if(!StringUtils.isEmpty(name)){
            wrapper.like("name",name);
        }
        if(!StringUtils.isEmpty(level)){
            wrapper.eq("level",level);
        }
        if(!StringUtils.isEmpty(joinDateBegin)){
            wrapper.ge("join_date",joinDateBegin);
        }
        if(!StringUtils.isEmpty(joinDateEnd)){
            wrapper.le("join_date",joinDateEnd);
        }
        //调用方法最终分页查询

        Page<Teacher> page = this.page(pageParam, wrapper);
        return page;
    }
}
